package com.ios.common.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ios.common.filehanlder.FileUpLoad;

public class FileUploadServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor of the object.
	 */
	public FileUploadServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			FileUpLoad.getInstance().fileUpLoad(request, response);
		} catch (Exception e) {
			String htmlCode = "<script type=\"text/javascript\" language=\"javascript\">"
					+ "alert('文件上传出错!!!')</script>";
			response.setCharacterEncoding("GBK");
			response.getWriter().write(htmlCode);
			e.printStackTrace();
		}

	}

	public void init() throws ServletException {
		// Put your code here
	}

}
